package com.project.zsxd.server.notice.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.project.zsxd.server.notice.entity.Notice;
import com.project.zsxd.server.notice.mapper.NoticeMapper;
import com.project.zsxd.server.notice.service.INoticeService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 公告表 服务实现类
 * </p>
 *
 * @author kaler
 * @since 2021-07-07
 */
@Service
public class NoticeServiceImpl extends ServiceImpl<NoticeMapper, Notice> implements INoticeService {


    @Override
    public Notice queryLastNoticeByType(String noticeType) {
        QueryWrapper<Notice> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("type", noticeType)
                .eq("status", "A")
                .orderByDesc("updated_time");
        List<Notice> notices = list(queryWrapper);
        if (notices == null || notices.isEmpty()) {
            return null;
        }
        return notices.get(0);
    }
}
